<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="editorDiv"></div>
    <button onclick="
    let data = {};
    let formInput = $('#form').children('input');
    for(let i = 0 ; i < formInput.length; i ++){
        let value = formInput.eq(i).val();
        if(value !== ''){
            if(formInput.eq(i).attr('match') === 'JSON'){
                try{
                    if(isNaN(value))throw 'e';
                    value = JSON.parse(value);
                }catch (e){
                    alert(`${formInput.eq(i).attr('name')}:输入json格式`);
                    return;
                }
            }
            data[formInput.eq(i).attr('name')] = value;
        }else{
            alert(`${formInput.eq(i).attr('name')}不能为空`);
            return;
        }
    }
    console.log(data);
    getAgent(getParams()['naive']).invoke('create',data).then(res=>{
        console.log(res);
           alert('新建成功');
           window.history.go(-1);
        });
">新建</button>
    <button onclick="window.history.go(-1);">返回</button>
</body>
<script src="../../frame/js/script_min.js"></script>
<script src="../../frame/js/util.js"></script>
<script type="text/javascript">

</script>
<script>
    if(getParams()["naive"]){
        let data = {};
        if(getParams()["id"]){
            data["id"] = getParams()["id"];
        }
        getAgent(getParams()["naive"]).invoke("detail",data).then(res=>{
            console.log(res);
            let form = `<form id="form"></form>`;
            $("#editorDiv").append(form);
            for(let i in res.args){
                console.log(res.args[i].describe.type);
                let p = `<span style="width:250px;display: inline-block;">${res.args[i].info}:${res.args[i].key}</span><input match="${res.args[i].describe.type}" style="width:500px" name="${res.args[i].key}" value="${res.args[i].value}"/><br/><br/>`;
                $("#form").append(p);
            }
        });
    }
</script>
</html>